<!DOCTYPE html>
<html>
<head>
    

    

    
<!-- Baidu Tongji -->
<script>var _hmt = _hmt || []</script>
<script async src="//hm.baidu.com/hm.js?a7c05ce530152d9866930ef4850ee566"></script>
<!-- End Baidu Tongji -->




    <meta charset="utf-8">
    
    
    
    <title>集合总结整理 | 神奇的鸭鸭の码农库 | 新知识要不断的总结记录成笔记，要多写，多画，能够清晰透彻的将知识讲给别人听，才是达到理解的层次。</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#765959">
    
    
    <meta name="keywords" content="java基础">
    <meta name="description" content="集合体系：Collection(单列集合的根接口) List(存取有序,有索引,可以重复) ArrayLis //底层数组实现，线程不安全，查改快，增删慢 LinkedList //底层链表实现，线程不安全，增删快，查改慢 Vector //底层数组实现，线程安全，增删改查都慢   set(存取无序,无索引,不可重复) HashSet //底层是哈希实现 LinkedHashSet //底层是链表">
<meta name="keywords" content="java基础">
<meta property="og:type" content="article">
<meta property="og:title" content="集合总结整理">
<meta property="og:url" content="http://magic_duck.oschina.io/2014/02/05/集合框架整理/index.html">
<meta property="og:site_name" content="神奇的鸭鸭の码农库">
<meta property="og:description" content="集合体系：Collection(单列集合的根接口) List(存取有序,有索引,可以重复) ArrayLis //底层数组实现，线程不安全，查改快，增删慢 LinkedList //底层链表实现，线程不安全，增删快，查改慢 Vector //底层数组实现，线程安全，增删改查都慢   set(存取无序,无索引,不可重复) HashSet //底层是哈希实现 LinkedHashSet //底层是链表">
<meta property="og:updated_time" content="2017-12-05T10:00:53.081Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="集合总结整理">
<meta name="twitter:description" content="集合体系：Collection(单列集合的根接口) List(存取有序,有索引,可以重复) ArrayLis //底层数组实现，线程不安全，查改快，增删慢 LinkedList //底层链表实现，线程不安全，增删快，查改慢 Vector //底层数组实现，线程安全，增删改查都慢   set(存取无序,无索引,不可重复) HashSet //底层是哈希实现 LinkedHashSet //底层是链表">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="/css/style.css?v=1.4.3">
    <script>window.lazyScripts=[]</script>
</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/avatar.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">神奇的鸭鸭</h5>
          <a href="mailto:702038338@qq.com" title="702038338@qq.com" class="mail">702038338@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://git.oschina.net/magic_duck" target="_blank" >
                <i class="icon icon-lg icon-gg-circle"></i>
                码云
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://www.zhihu.com/people/shen-qi-de-ya-ya" target="_blank" >
                <i class="icon icon-lg icon-twitter"></i>
                知乎
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/404.html"  >
                <i class="icon icon-lg icon-link"></i>
                404页面测试
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">集合总结整理</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">集合总结整理</h1>
        <h5 class="subtitle">
            
                <time datetime="2014-02-04T16:00:00.000Z" itemprop="datePublished" class="page-time">
  2014-02-05
</time>


            
        </h5>
    </div>

    

</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#集合体系："><span class="post-toc-number">1.</span> <span class="post-toc-text">集合体系：</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Collection-单列集合的根接口"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">Collection(单列集合的根接口)</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Collection接口"><span class="post-toc-number">2.</span> <span class="post-toc-text">Collection接口</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Iterator迭代器的基本功能："><span class="post-toc-number">3.</span> <span class="post-toc-text">Iterator迭代器的基本功能：</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#List接口"><span class="post-toc-number">4.</span> <span class="post-toc-text">List接口</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Vector集合-了解-被淘汰的"><span class="post-toc-number">4.1.</span> <span class="post-toc-text">Vector集合(了解)(被淘汰的)</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#LinkedList集合"><span class="post-toc-number">4.2.</span> <span class="post-toc-text">LinkedList集合</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#ArrayList集合"><span class="post-toc-number">4.3.</span> <span class="post-toc-text">ArrayList集合</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Set接口"><span class="post-toc-number">5.</span> <span class="post-toc-text">Set接口</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#HashSet集合"><span class="post-toc-number">5.1.</span> <span class="post-toc-text">HashSet集合</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#LinkedHashSet集合"><span class="post-toc-number">5.2.</span> <span class="post-toc-text">LinkedHashSet集合</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#TreeSet集合"><span class="post-toc-number">5.3.</span> <span class="post-toc-text">TreeSet集合</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#Map接口"><span class="post-toc-number">6.</span> <span class="post-toc-text">Map接口</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#下面对map迭代的优化："><span class="post-toc-number">6.1.</span> <span class="post-toc-text">下面对map迭代的优化：</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#HashMap类-LinkedHashMap类-TreeMap类"><span class="post-toc-number">6.2.</span> <span class="post-toc-text">HashMap类  LinkedHashMap类  TreeMap类</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#集合工具类Collections的功能"><span class="post-toc-number">7.</span> <span class="post-toc-text">集合工具类Collections的功能</span></a></li></ol>
        </nav>
    </aside>
    
<article id="post-集合框架整理"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">集合总结整理</h1>
        <div class="post-meta">
            <time class="post-time" title="2014年02月05日 0:00" datetime="2014-02-04T16:00:00.000Z"  itemprop="datePublished">2014-02-05</time>

            


            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h2 id="集合体系："><a href="#集合体系：" class="headerlink" title="集合体系："></a>集合体系：</h2><h3 id="Collection-单列集合的根接口"><a href="#Collection-单列集合的根接口" class="headerlink" title="Collection(单列集合的根接口)"></a>Collection(单列集合的根接口)</h3><ul>
<li>List(存取有序,有索引,可以重复)<ul>
<li>ArrayLis //底层数组实现，线程不安全，查改快，增删慢</li>
<li>LinkedList //底层链表实现，线程不安全，增删快，查改慢</li>
<li>Vector //底层数组实现，线程安全，增删改查都慢</li>
</ul>
</li>
<li>set(存取无序,无索引,不可重复)<ul>
<li>HashSet //底层是哈希实现</li>
<li>LinkedHashSet //底层是链表实现,但也可以保证元素唯一</li>
<li>TreeSet //底层是二叉树实现</li>
</ul>
</li>
<li>Map(双列集合的根接口)<ul>
<li>HashMap //底层是哈希算法，针对键<ul>
<li>LinkedHashMap //底层是链表，针对键</li>
</ul>
</li>
<li>TreeMap //底层是二叉树算法，针对键</li>
</ul>
</li>
</ul>
<blockquote>
<p>附带知识：迭代器：Iterator  比较器：Comparator 工具类：Collections</p>
</blockquote>
<hr>
<h2 id="Collection接口"><a href="#Collection接口" class="headerlink" title="Collection接口"></a>Collection接口</h2><p>由于Collection是接口，所以得实现类去创建对象，这里选择ArrayList：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Collection c = <span class="keyword">new</span> ArrayList();</div></pre></td></tr></table></figure></p>
<p>Collection中的基本功能：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">add</span><span class="params">(E e)</span> <span class="comment">//添加1个元素到集合中，List体系下add方法永远返回true</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">remove</span><span class="params">(Object o)</span> <span class="comment">//删除1个指定元素，删除成功true 失败false</span></span></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">clear</span><span class="params">()</span> <span class="comment">//清空集合所有内容</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">contains</span><span class="params">(Object o)</span> <span class="comment">//判断是否包含该元素，是返回true，否则false</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">isEmpty</span><span class="params">()</span> <span class="comment">//判断集合是否是空的，是返回true，否则false</span></span></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">size</span><span class="params">()</span> <span class="comment">//返回集合中元素的个数</span></span></div></pre></td></tr></table></figure></p>
<p>遍历集合时，如果不使用迭代器，可以使用Collection中的toArray方法：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Object[] toArray()<span class="comment">//将集合转换成数组(返回的Object数组(多态好处))</span></div></pre></td></tr></table></figure></p>
<p>下面是Collection中带All的功能测试：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">addAll</span><span class="params">(Collection c)</span><span class="comment">//将一个集合的元素全部拷贝到当前集合</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">removeAll</span><span class="params">(Collection c)</span><span class="comment">//删除和传入集合相同的元素(删除交集)</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">containsAll</span><span class="params">(Collection c)</span><span class="comment">//判断是否包含传入集合的所有元素，</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">retainAll</span><span class="params">(Collection c)</span><span class="comment">//移除所有和传入集合非交集的元素</span></span></div><div class="line"><span class="function">Iterator&lt;E&gt; <span class="title">iterator</span><span class="params">()</span><span class="comment">//返回当前集合的元素上进行迭代的迭代器</span></span></div></pre></td></tr></table></figure></p>
<hr>
<h2 id="Iterator迭代器的基本功能："><a href="#Iterator迭代器的基本功能：" class="headerlink" title="Iterator迭代器的基本功能："></a>Iterator迭代器的基本功能：</h2><p>由于Iterator是接口，这里通过ArrayList中的iterator方法创建Iterator对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">Collection c = <span class="keyword">new</span> ArrayList();  </div><div class="line">Iterator it = c.iterator();<span class="comment">//注意多态特性：编译看左边 运行看右边</span></div><div class="line">``` </div><div class="line"></div><div class="line">下面是Iterator中的功能：</div><div class="line">``` java</div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">hasNext</span><span class="params">()</span><span class="comment">//如果仍有元素可以迭代，则返回 true。否则抛出异常</span></span></div><div class="line"><span class="function">E <span class="title">next</span><span class="params">()</span><span class="comment">//返回迭代器的下一个元素</span></span></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">remove</span><span class="params">()</span><span class="comment">//从迭代器指向的集合中移除迭代器返回的最后一个元素</span></span></div></pre></td></tr></table></figure></p>
<blockquote>
<p>分析迭代器源码，可以知道其指针迭代原理，详见源码总结。</p>
</blockquote>
<hr>
<h2 id="List接口"><a href="#List接口" class="headerlink" title="List接口"></a>List接口</h2><p>以下是List集合体系下的三个常用子类</p>
<ul>
<li>ArrayList</li>
<li>LinkedList</li>
<li>Vecter</li>
</ul>
<p>由于List是接口，所以得由实现类去创建对象，这里选择ArrayList<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">List ls = <span class="keyword">new</span> ArrayList();</div></pre></td></tr></table></figure></p>
<p>List中的特有功能：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//(此方法会将该位置的元素和后续元素向右移动，其索引+1)</span></div><div class="line"><span class="comment">//(如果index &gt; size || index &lt; 0 将会抛出IndexOutOfBoundsException异常)</span></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> index,E element)</span><span class="comment">//在index位置上插入element元素</span></span></div><div class="line"><span class="function">E <span class="title">remove</span><span class="params">(<span class="keyword">int</span> index)</span><span class="comment">//删除指定index上的元素，并将该元素返回(后续元素将左移)</span></span></div><div class="line"><span class="function">E <span class="title">get</span><span class="params">(<span class="keyword">int</span> index)</span><span class="comment">//返回指定index位置上的元素</span></span></div><div class="line"><span class="function">E <span class="title">set</span><span class="params">(<span class="keyword">int</span> index,E element)</span><span class="comment">//将指定element元素替换index上的元素</span></span></div><div class="line"><span class="function">ListIterator&lt;E&gt; <span class="title">listIterator</span><span class="params">()</span></span>;<span class="comment">//返回此列表元素的列表迭代器(按适当顺序)</span></div></pre></td></tr></table></figure></p>
<p><strong>为什么在List中要定义listIteratoe迭代器：</strong></p>
<p>因为当我们使用Iterator迭代器在进行迭代过程中如果增加元素，<br>就会发生并发修改异常(ConcurrentModificationException并发修改异常),<br>而ListIterator则解决了这个问题。</p>
<p>下面是listIterator迭代器的基本功能(不重要)：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">hasNext</span><span class="params">()</span><span class="comment">//是否有下一个</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">hasPrevious</span><span class="params">()</span><span class="comment">//是否有前一个</span></span></div><div class="line"><span class="function">Object <span class="title">next</span><span class="params">()</span><span class="comment">//返回下一个元素</span></span></div><div class="line"><span class="function">Object <span class="title">previous</span><span class="params">()</span><span class="comment">//返回上一个元素</span></span></div></pre></td></tr></table></figure></p>
<h3 id="Vector集合-了解-被淘汰的"><a href="#Vector集合-了解-被淘汰的" class="headerlink" title="Vector集合(了解)(被淘汰的)"></a>Vector集合(了解)(被淘汰的)</h3><p>直接创建Vector对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Vector v = <span class="keyword">new</span> Vector();</div></pre></td></tr></table></figure></p>
<p>下面是Vector的特有功能(特有自己的迭代方法)：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addElement</span><span class="params">(E obj)</span><span class="comment">//结果同add</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">elementAt</span><span class="params">(<span class="keyword">int</span> index)</span><span class="comment">//结果同hasNext</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> Enumeration <span class="title">elements</span><span class="params">()</span><span class="comment">//结果同next</span></span></div></pre></td></tr></table></figure></p>
<h3 id="LinkedList集合"><a href="#LinkedList集合" class="headerlink" title="LinkedList集合"></a>LinkedList集合</h3><p>直接创建LinkedList对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">LinkedList list = <span class="keyword">new</span> LinkedList(); </div><div class="line">``` </div><div class="line"></div><div class="line">下面是LinkedList的特有功能(特有自己的链式方法)：  </div><div class="line">``` java</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addFirst</span><span class="params">(E e)</span><span class="comment">//添加到链表头</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addLast</span><span class="params">(E e)</span><span class="comment">//添加到链表尾</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">getFirst</span><span class="params">()</span><span class="comment">//获取链表头的元素</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">getLast</span><span class="params">()</span><span class="comment">//获取链表尾的元素</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">removeFirst</span><span class="params">()</span><span class="comment">//删除链表头的元素</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">removeLast</span><span class="params">()</span><span class="comment">//删除链表尾的元素</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> E <span class="title">get</span><span class="params">(<span class="keyword">int</span> index)</span><span class="comment">//获取指定索引的元素(慢)</span></span></div></pre></td></tr></table></figure></p>
<h3 id="ArrayList集合"><a href="#ArrayList集合" class="headerlink" title="ArrayList集合"></a>ArrayList集合</h3><p>直接创建ArrayList对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ArrayList list = <span class="keyword">new</span> ArrayList();</div></pre></td></tr></table></figure></p>
<p>下面是ArrayList的特有功能(没用)：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span>&lt;T&gt; T[] toArray(T[] a)<span class="comment">//将集合转换成数组,类型是泛型</span></div></pre></td></tr></table></figure></p>
<blockquote>
<p>当集合转换数组时，数组长度如果是小于等于集合的size时，转换后的数组长度等于集合size</p>
</blockquote>
<hr>
<h2 id="Set接口"><a href="#Set接口" class="headerlink" title="Set接口"></a>Set接口</h2><p>以下是Set集合体系下的两个常用子类</p>
<ul>
<li>HashSet<ul>
<li>LinkedHashSet</li>
</ul>
</li>
<li>TreeSet</li>
</ul>
<p>Set接口中的方法与Collection中的一模一样，没有发现特有方法。</p>
<h3 id="HashSet集合"><a href="#HashSet集合" class="headerlink" title="HashSet集合"></a>HashSet集合</h3><p>直接创建HashSet对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">HashSet hs = <span class="keyword">new</span> HashSet(); </div><div class="line">``` </div><div class="line"></div><div class="line">**HashSet可以保证元素的唯一性，下面进行说明：**</div><div class="line"></div><div class="line"><span class="number">1</span>. 测试HashSet存储字符串保证元素唯一性：</div><div class="line"></div><div class="line">``` java</div><div class="line"><span class="keyword">boolean</span> b1 = hs.add(<span class="string">"a"</span>);<span class="comment">//第一次存入返回true</span></div><div class="line"><span class="keyword">boolean</span> b2 = hs.add(<span class="string">"a"</span>);<span class="comment">//当向set集合中存储重复元素的时候返回为false</span></div></pre></td></tr></table></figure></p>
<ol>
<li>测试HashSet存储自定义对象保证元素唯一性(失败了)：</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">HashSet&lt;Person&gt; hs = new HashSet&lt;&gt;();</div><div class="line">hs.add(new Person(&quot;张三&quot;, 23));</div><div class="line">hs.add(new Person(&quot;张三&quot;, 23));   </div><div class="line">hs.add(new Person(&quot;李四&quot;, 24)); </div><div class="line">--------------------------------------</div><div class="line">Output：</div><div class="line">name=张三,age=23; name=张三,age=23; name=李四,age=24;</div></pre></td></tr></table></figure>
<ol>
<li>分析：HashSet并不能保证元素的唯一性，因为自定义对象判重时对比的是地址值，所以尝试重写Person中的equals方法(失败了)：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line">通过eclipse重写的方法：</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">equals</span><span class="params">(Object obj)</span> </span>&#123;</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">this</span> == obj)</div><div class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">    <span class="keyword">if</span> (obj == <span class="keyword">null</span>)</div><div class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    <span class="keyword">if</span> (getClass() != obj.getClass())</div><div class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    Person other = (Person) obj;</div><div class="line">    <span class="keyword">if</span> (age != other.age)</div><div class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    <span class="keyword">if</span> (name == <span class="keyword">null</span>) &#123;</div><div class="line">        <span class="keyword">if</span> (other.name != <span class="keyword">null</span>)</div><div class="line">            <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (!name.equals(other.name))</div><div class="line">        <span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">    <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">&#125;</div><div class="line">--------------------------------------</div><div class="line">Output：</div><div class="line">name=张三,age=<span class="number">23</span>; name=张三,age=<span class="number">23</span>; name=李四,age=<span class="number">24</span>;</div></pre></td></tr></table></figure>
<ol>
<li>结果并没有改变，检查发下equals并没有被调用，因此去尝试重写hashCode方法(成功)：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">hashCode</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div><div class="line">--------------------------------------</div><div class="line">Output：</div><div class="line">name=张三,age=<span class="number">23</span>; name=李四,age=<span class="number">24</span>;</div></pre></td></tr></table></figure>
<ol>
<li>也就是说，只有hashCode值一样的时候才会去调用equals方法，所以为了减少调用equals方法的次数，应该用更复杂的算法去重写hashCode方法：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">通过eclipse重写的方法：</div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">hashCode</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">final</span> <span class="keyword">int</span> prime = <span class="number">31</span>;</div><div class="line">    <span class="keyword">int</span> result = <span class="number">1</span>;</div><div class="line">    result = prime * result + age;</div><div class="line">    result = prime * result + ((name == <span class="keyword">null</span>) ? <span class="number">0</span> : name.hashCode());</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div><div class="line">--------------------------------------</div><div class="line">Output：</div><div class="line">name=张三,age=<span class="number">23</span>; name=李四,age=<span class="number">24</span>;</div></pre></td></tr></table></figure>
<p><strong>结论1：</strong>我们使用Set集合都是需要去掉重复元素的, 如果在存储的时候逐个equals()比较, 效率较低,哈希算法提高了去重复的效率, 降低了使用equals()方法的次数。</p>
<p><strong>结论2：</strong>当HashSet调用add()方法存储对象的时候, 先调用对象的hashCode()方法得到一个哈希值, 然后在集合中查找是否有哈希值相同的对象。</p>
<p><strong>结论3：</strong>如果没有哈希值相同的对象就直接存入集合，如果有哈希值相同的对象, 就和哈希值相同的对象逐个进行equals()比较,比较结果为false就存入, true则不存。</p>
<hr>
<h3 id="LinkedHashSet集合"><a href="#LinkedHashSet集合" class="headerlink" title="LinkedHashSet集合"></a>LinkedHashSet集合</h3><p>LinkedHashSet可以保证存入顺序，也就是怎么存就能怎么取</p>
<h3 id="TreeSet集合"><a href="#TreeSet集合" class="headerlink" title="TreeSet集合"></a>TreeSet集合</h3><p>TreeSet是用来排序的, 可以指定一个顺序, 对象存入之后会按照指定的顺序排列。</p>
<p>直接创建TreeSet对象：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">TreeSet v = <span class="keyword">new</span> TreeSet();</div></pre></td></tr></table></figure></p>
<p><strong>测试TreeSet的排序功能：</strong></p>
<ol>
<li>测试TreeSet存储数字的排序功能：</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">TreeSet&lt;Integer&gt; ts = new TreeSet&lt;&gt;();</div><div class="line">    ts.add(3);</div><div class="line">    ts.add(3);</div><div class="line">    ts.add(1);</div><div class="line">    ts.add(2);</div><div class="line">System.out.println(ts);</div><div class="line">--------------------------------------</div><div class="line">Output：</div><div class="line">1,2,3</div></pre></td></tr></table></figure>
<ol>
<li>阅读API可以知道，TreeSet类是使用元素的自然顺序对元素进行排序，或者根据创建set时提供的Comparator进行排序，具体取决于使用的构造方法。也就是说排序是通过实现Comparator方法下compare(比较器)方法实现的，所以去查找Integer类中有无实现Comparator接口中的compare方法：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>&#123;</div><div class="line">    <span class="keyword">return</span> (x &lt; y) ? -<span class="number">1</span> : ((x == y) ? <span class="number">0</span> : <span class="number">1</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>在使用TreeSet存储对象的时候,add()方法内部就会自动调用compareTo()方法进行比较, 根据比较结果使用二叉树形式进行存储，实验可知：</li>
</ol>
<ul>
<li>当compareTo方法返回0的时候集合只有一个元素</li>
<li>当compareTo方法返回正数的时候集合会怎么存怎么取</li>
<li>当compareTo方法返回负数的时候集合会倒序存储</li>
</ul>
<p>上面的写法并不是太好，因为需要让自己定义的类去实现Comparator接口然后重写compare方法，所以TreeSet提供了更直接的构造方法：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">TreeSet(Collection&lt;? extends E&gt; c)  </div><div class="line">``` </div><div class="line"></div><div class="line">所以我们可以直接通过<span class="keyword">new</span>匿名内部类的方法去实现compare方法</div><div class="line">``` java</div><div class="line">TreeSet&lt;Character&gt; ts = <span class="keyword">new</span> TreeSet&lt;&gt;(<span class="keyword">new</span> Comparator&lt;Character&gt;() &#123;</div><div class="line">	<span class="meta">@Override</span></div><div class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">compare</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y)</span> </span>&#123;</div><div class="line">		    <span class="keyword">return</span> (x &lt; y) ? -<span class="number">1</span> : ((x == y) ? <span class="number">0</span> : <span class="number">1</span>);</div><div class="line">	&#125;</div><div class="line">&#125;);</div></pre></td></tr></table></figure>
<p>这便是通过匿名内部类的形式构建了一个比较器，如果传入了Comparator的子类对象，那么TreeSet就会按照比较器中的顺序排序</p>
<hr>
<h2 id="Map接口"><a href="#Map接口" class="headerlink" title="Map接口"></a>Map接口</h2><p>以下是Map集合体系下的三个常用子类：</p>
<ul>
<li>HashMap</li>
<li>LinkedHashMap</li>
<li>TreeMap</li>
</ul>
<p>Map接口的特有功能：<br>由于Map是接口，所以得由子类去创建对象，这里选择HashMap<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Map&lt;String, Integer&gt; m = <span class="keyword">new</span> HashMap&lt;&gt;();</div></pre></td></tr></table></figure></p>
<p>下面开始实验Map中的特有功能：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="function">V <span class="title">put</span><span class="params">(K key,V value)</span><span class="comment">//添加元素(第一次存储返回null,不是第一次存,就只改值,并返回值)</span></span></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">clear</span><span class="params">()</span><span class="comment">//移除所有的键值对元素</span></span></div><div class="line"><span class="function">V <span class="title">remove</span><span class="params">(Object key)</span><span class="comment">//根据键删除键值对元素，并把值返回</span></span></div><div class="line"><span class="function">oolean <span class="title">containsKey</span><span class="params">(Object key)</span><span class="comment">//判断集合是否包含指定的键</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">containsValue</span><span class="params">(Object value)</span><span class="comment">//判断集合是否包含指定的值</span></span></div><div class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">isEmpty</span><span class="params">()</span><span class="comment">//判断集合是否为空</span></span></div><div class="line"><span class="function">Set&lt;Map.Entry&lt;K,V&gt;&gt; <span class="title">entrySet</span><span class="params">()</span><span class="comment">//将键值对封装成对象再封装到Set集合中(map.Entry是内部类)</span></span></div><div class="line"><span class="function">    V <span class="title">get</span><span class="params">(Object key)</span><span class="comment">//根据键获取值</span></span></div><div class="line"><span class="function">    Set&lt;K&gt; <span class="title">keySet</span><span class="params">()</span><span class="comment">//获取集合中所有键的集合</span></span></div><div class="line"><span class="function">    Collection&lt;V&gt; <span class="title">values</span><span class="params">()</span><span class="comment">//获取集合中所有值的集合</span></span></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">size</span><span class="params">()</span><span class="comment">//返回集合中的键值对的个数</span></span></div></pre></td></tr></table></figure></p>
<p>Map接口和Collection接口的不同点：</p>
<ul>
<li>Map是双列的,Collection是单列的</li>
<li>Map的键唯一,Collection的子体系Set是唯一的</li>
<li>Map集合的数据结构值针对键有效，跟值无关;Collection集合的数据结构是针对元素有效</li>
</ul>
<h3 id="下面对map迭代的优化："><a href="#下面对map迭代的优化：" class="headerlink" title="下面对map迭代的优化："></a>下面对map迭代的优化：</h3><ol>
<li>普通迭代：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//先将键和值封装成了Entry对象,存储在Set集合中(Map.Entry说明Entry是Map的内部接口)</span></div><div class="line">Set&lt;Map.Entry&lt;String, Integer&gt;&gt; entrySet = map.entrySet();</div><div class="line"><span class="comment">//创建迭代器对象</span></div><div class="line">Iterator&lt;Map.Entry&lt;String, Integer&gt;&gt; it = entrySet.iterator();</div><div class="line"><span class="keyword">while</span>(it.hasNext())&#123;</div><div class="line">	<span class="comment">//获取每个Entry对象</span></div><div class="line">	Map.Entry&lt;String, Integer&gt; en = it.next();</div><div class="line">	String key = en.getKey();<span class="comment">//根据键值对对象获取键</span></div><div class="line">	Integer value = en.getValue();<span class="comment">//根据键值对对象获取值</span></div><div class="line">	System.out.println(key+<span class="string">":"</span>+value);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>通过查找API，在HashMap类下查找到Entry<k,v>类，其实现了Map.Entry<k,v>接口<br>使用foreach优化写法：</k,v></k,v></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//直接用Entry对象去迭代</span></div><div class="line"><span class="keyword">for</span>(Entry&lt;String, Integer&gt; en : map.entrySet())&#123;</div><div class="line">	System.out.println(en.getKey()+<span class="string">":"</span>+en.getValue());</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>HashMap嵌套HashMap的迭代</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//定义计应3班</span></div><div class="line">HashMap&lt;Student, String&gt; jy3 = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line"><span class="comment">//定义计算机学院</span></div><div class="line">HashMap&lt;HashMap&lt;Student, String&gt;, String&gt; jy = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line"><span class="keyword">for</span>(HashMap&lt;Student, String&gt; h : jy.keySet())&#123;</div><div class="line">	String value = jy.get(h);</div><div class="line">	<span class="keyword">for</span>(Student key : h.keySet())&#123;</div><div class="line">		String value2 = h.get(key);</div><div class="line">		System.out.println(key + <span class="string">"="</span> + value2 + <span class="string">"="</span> + value);</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="HashMap类-LinkedHashMap类-TreeMap类"><a href="#HashMap类-LinkedHashMap类-TreeMap类" class="headerlink" title="HashMap类  LinkedHashMap类  TreeMap类"></a>HashMap类  LinkedHashMap类  TreeMap类</h3><p>没有其他重要的特殊功能，需要知道的是Set的底层是由HashMap实现的</p>
<p><strong>HashMap和Hashtable的区别</strong></p>
<ul>
<li>Hashtable是JDK1.0版本出现的,是线程安全的,效率低,</li>
<li>HashMap是JDK1.2版本出现的,是线程不安全的,效率高</li>
<li>Hashtable不可以存储null键和null值,</li>
<li>HashMap可以存储null键和null值</li>
</ul>
<hr>
<h2 id="集合工具类Collections的功能"><a href="#集合工具类Collections的功能" class="headerlink" title="集合工具类Collections的功能"></a>集合工具类Collections的功能</h2><p>抽取了其中最实用的5个功能：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; <span class="function"><span class="keyword">void</span> <span class="title">sort</span><span class="params">(List&lt;T&gt; list)</span><span class="comment">//排序</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; <span class="keyword">int</span> <span class="title">binarySearch</span><span class="params">(List&lt;?&gt; list,T key)</span><span class="comment">//二分查找(二分必须先排序)</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> &lt;T&gt; T <span class="title">max</span><span class="params">(Collection&lt;?&gt; coll)</span><span class="comment">//获取最大值</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">reverse</span><span class="params">(List&lt;?&gt; list)</span><span class="comment">//反转</span></span></div><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">shuffle</span><span class="params">(List&lt;?&gt; list)</span><span class="comment">//随机</span></span></div></pre></td></tr></table></figure></p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2017-12-05T10:00:53.081Z" itemprop="dateUpdated">2017年12月5日 18:00</time>
</span><br>


        如要转载请注明出处：<a href="/2014/02/05/集合框架整理/" target="_blank" rel="external">http://magic_duck.oschina.io/2014/02/05/集合框架整理/</a>
    </div>
    <footer>
        <a href="http://magic_duck.oschina.io">
            <img src="/img/avatar.jpg" alt="神奇的鸭鸭">
            神奇的鸭鸭
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/java基础/">java基础</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&title=《集合总结整理》 — 神奇的鸭鸭の码农库&pic=http://magic_duck.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&title=《集合总结整理》 — 神奇的鸭鸭の码农库&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://magic_duck.oschina.io/2014/02/05/集合框架整理/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《集合总结整理》 — 神奇的鸭鸭の码农库&url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&via=http://magic_duck.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2016/11/02/szpt1011/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">2017热身赛第二场——分解自然数</h4>
      </a>
    </div>
  

  
</nav>



    







</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        我只要一角钱~ ~
        <i class="icon icon-quote-right"></i>
    </h3>
    <ul class="reward-items">
        
        <li>
            <img src="/img/wechat.png" title="微信打赏二维码" alt="微信打赏二维码">
            <p>微信</p>
        </li>
        

        
        <li>
            <img src="/img/alipay.jpg" title="支付宝打赏二维码" alt="支付宝打赏二维码">
            <p>支付宝</p>
        </li>
        
    </ul>
</div>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            <span><a href="" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            <span>博客内容遵循 <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p>
            <span>Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://git.oschina.net/z77z" target="_blank">邹海清</a></span>
            <span>神奇的鸭鸭の码农库 &copy; 2017</span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&title=《集合总结整理》 — 神奇的鸭鸭の码农库&pic=http://magic_duck.oschina.io/img/avatar.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&title=《集合总结整理》 — 神奇的鸭鸭の码农库&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://magic_duck.oschina.io/2014/02/05/集合框架整理/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《集合总结整理》 — 神奇的鸭鸭の码农库&url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/&via=http://magic_duck.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://magic_duck.oschina.io/2014/02/05/集合框架整理/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=http://magic_duck.oschina.io/2014/02/05/集合框架整理/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };



lazyScripts.push('//s95.cnzz.com/z_stat.php?id=1261081671&web_id=1261081671')

</script>

<script src="/js/main.min.js?v=1.4.3"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="/js/search.min.js?v=1.4.3" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>


</body>
</html>
